package com.wsfk.ssm.entity;

import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.time.DateUtils;

public class HandBook {

	public final static String UNCREATE = "uncreate";		//未创建 
	public final static String UNFINISHED = "unfinish";	//未完成
	public final static String FINISHED = "finished";	//完成
	public final static String UNPUBLISH = "unpublish";		//未发布
	public final static String STOP_PUBLISH = "stop_publish";//停止发布
	public final static String  PUBLISH = "published";		//已发布
	

	private String id;			
	private String name;		//手册名称
	private String author;		//作者（默认为userName）
	private Date createDate;	//创建时间
	private String downNum;		//下载码
	private String towCode;		//二维码地址
	private String userId;		//用户ID
	private Date publishDate;	//发布时间
	private String  version;	//版本号
	private String publishStatus;	//发布状态
	private Date stopDate;		//结束时间
	private String createStatus;//创建状态
	private String bookdir;		//图书所存放的地址
	
	
	
	public HandBook() {
		super();
		
	}
	
	public HandBook(String id, String name, String author, Date createDate,
			String downNum, String towCode, String userId, Date publishDate,
			String version, String publishStatus, Date stopDate,
			String createStatus,String bookdir) {
		super();
		this.id = id;
		this.name = name;
		this.author = author;
		this.createDate = createDate;
		this.downNum = downNum;
		this.towCode = towCode;
		this.userId = userId;
		this.publishDate = publishDate;
		this.version = version;
		this.publishStatus = publishStatus;
		this.stopDate = stopDate;
		this.createStatus = createStatus;
		this.bookdir =bookdir;
	}

	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getVersion() {
		return version;
	}
	public void setVersion(String version) {
		this.version = version;
	}
	public String getPublishStatus() {
		return publishStatus;
	}
	public void setPublishStatus(String publishStatus) {
		this.publishStatus = publishStatus;
	}
	public Date getStopDate() {
		return stopDate;
	}
	public void setStopDate(Date stopDate) {
		this.stopDate = stopDate;
	}
	public String getCreateStatus() {
		return createStatus;
	}
	public void setCreateStatus(String createStatus) {
		this.createStatus = createStatus;
	}
	public String getDownNum() {
		return downNum;
	}

	public String getTowCode() {
		return towCode;
	}

	public void setTowCode(String towCode) {
		this.towCode = towCode;
	}

	public Date getPublishDate() {
		return publishDate;
	}

	public void setPublishDate(Date publishDate) {
		this.publishDate = publishDate;
	}

	public void setDownNum(String downNum) {
		this.downNum = downNum;
	}

	public String getBookdir() {
		return bookdir;
	}

	public void setBookdir(String bookdir) {
		this.bookdir = bookdir;
	}

	@Override
	public String toString() {
		return "HandBook [id=" + id + ", name=" + name + ", author=" + author
				+ ", createDate=" + createDate + ", downNum=" + downNum
				+ ", towcode=" + towCode + ", userId=" + userId
				+ ", publishdate=" + publishDate + ", version=" + version
				+ ", publishStatus=" + publishStatus + ", stopDate=" + stopDate
				+ ", createStatus=" + createStatus + ",bookdir"+bookdir+"]";
	}

	public static HandBook creatNewBook(String r ,String userid) {
		HandBook book = new HandBook();
		book.setCreateStatus(HandBook.UNCREATE);
		book.setDownNum(r);
		book.setPublishStatus(HandBook.UNPUBLISH);
		book.setUserId(userid);
		book.setVersion("1");
		return book;
	}
	public void renewal(){
		//这里应该在当前日期上加30天
		//this.stopDate = DateUtils.addDays(this.stopDate, 30);
		this.stopDate = DateUtils.addDays(new Date(), 30);
	}


	@Override
	public boolean equals(Object obj) {
		HandBook book = (HandBook) obj;
		return new EqualsBuilder()
		.append(this.id, book.id)
		.append(this.bookdir, book.bookdir)
		.append(this.createStatus, book.createStatus)
		.append(this.version, book.version)
		.isEquals();
	}
	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}
}
